package com.csu.servlet;

import com.csu.entiry.Book;
import com.csu.entiry.BorrowInfo;
import com.csu.service.BookService;
import com.csu.service.BorrowInfoService;
import com.csu.service.impl.BookServiceImpl;
import com.csu.service.impl.BorrowInfoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "BorrowInfoDetailServlet", urlPatterns = "/BorrowInfoDetailServlet")
public class BorrowInfoDetailServlet extends HttpServlet {
    private BorrowInfoService borrowInfoService = new BorrowInfoServiceImpl();
    private BookService bookService = new BookServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int borrowId = Integer.parseInt(req.getParameter("borrowId"));
        BorrowInfo borrowInfo = borrowInfoService.getByBorrowId(borrowId);
        req.getSession().setAttribute("BorrowInfo", borrowInfo);
        Book book = bookService.getById(borrowInfo.getBookId());
        req.getSession().setAttribute("book", book);
        req.getRequestDispatcher("/borrowInfoDetail.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
